# -*- Mode: Python -*- vi:si:et:sw=4:sts=4:ts=4:syntax=python
from cerbero.utils import shell

class Recipe(recipe.Recipe):
    name = 'tremor'
    version = '1.2.1+r19427'
    stype = SourceType.TARBALL
    url = 'https://gstreamer.freedesktop.org/data/src/mirror/tremor-1.2.1+r19427.tar.xz'
    tarball_checksum = "4bdbb655ea0e6a70b0ad20f90f747d18936d80a4366020581eb7fc5d1b3550bf"
    licenses = [{License.BSD_like: ['COPYING']}]
    deps = ['libogg']
    config_sh = 'sh autogen.sh'
    patches = ['tremor/0001-Prevent-symbol-conflicts.patch',
               'tremor/0002-Try-fixing-shared-build.patch',
               'tremor/0003-Map-remaining-symbol-too.patch',
               'tremor/0004-Fix-build-with-the-Android-NDK-for-x86.patch',
               'tremor/0005-configure-check-for-machine-endianness.patch',
               'tremor/0006-tremor-floor-mapping-residue-function-renaming.patch',
               'tremor/0007-tremor-more-function-renaming.patch',
               'tremor/0008-fix-more-duplicated-symbols.patch']

    files_libs = ['libvorbisidec']
    files_devel = [
        'include/tremor', 'lib/pkgconfig/vorbisidec.pc']

    def prepare(self):
        if self.config.target_arch == Architecture.ARMv7:
            if self.config.target_platform != Platform.IOS:
                self.append_env('CFLAGS', '-Wa,-mimplicit-it=thumb')
        elif self.config.target_arch == Architecture.ARM:
            # Disable thumb code generation
            self.append_env('CFLAGS', '-marm')

    async def configure(self):
        if self.config.target_platform == Platform.IOS:
            shell.replace(os.path.join(self.build_dir, 'configure.in'), {'-D_ARM_ASSEM_':''})
        await super(recipe.Recipe, self).configure()
